﻿using UnityEngine;
using System.Collections.Generic;
using System;

[Serializable]
public struct Point
{
    public int x;
    public int y;

    public Point(int x, int y) { this.x = x; this.y = y; }

    public override string ToString()
    {
        return string.Format("X: {0} Y: {1}", x, y);
    }
}

[Serializable]
public class ColorSerializable
{
    public float r { get; set; }
    public float g { get; set; }
    public float b { get; set; }
    public float a { get; set; }

    public Color color { get { return new Color(r, g, b, a); } }

    public ColorSerializable()
    {
        SetEverething(0, 0, 0, 1);
    }

    public ColorSerializable(float r, float g, float b)
    {
        SetEverething(r, g, b, 1);
    }

    public ColorSerializable(float r, float g, float b, float a)
    {
        SetEverething(r, g, b, a);
    }

    public ColorSerializable(Color color)
    {
        SetEverething(color.r, color.g, color.b, color.a);
    }

    protected void SetEverething(float r, float g, float b, float a)
    {
        this.r = r;
        this.g = g;
        this.b = b;
        this.a = a;
    }

    public static implicit operator ColorSerializable(Color color)
    {
        return new ColorSerializable(color);
    }
}

public class Counter
{
    private uint m_Count = 0;

    public void Increment() { if (m_Count != uint.MaxValue) ++m_Count; }
    public void Decrement() { if (m_Count > 0) --m_Count; }
    public bool IsZero() { return m_Count <= 0; }
}

public static class Print
{
    public static string ActionChain(Queue<Board.Action> chain)
    {
        string output = "";
        foreach (var action in chain)
        {
            switch (action.type)
            {
                case Board.Action.Type.Add:
                    //sound.PlayWhistle();//
                    output += "Add\n";
                    for (int i = 0; i < action.from.Count; i++)
                    {
                        output += string.Format("x: {0} y: {1} type: {2}\n", action.from[i].x, action.from[i].y, action.gemTypes[i]);
                    }
                    break;
                case Board.Action.Type.Remove:
                    //sound.PlayExplosion();
                    output += "Remove\n";
                    for (int i = 0; i < action.lines.Count; i++)
                    {
                        output += string.Format("Line size: {2} type: {1} player: {0}\n", action.playerID, action.lines[i].Count, action.gemTypes[i]);
                    }
                    break;
                case Board.Action.Type.Swap:
                    output += "Swap\n";
                    for (int i = 0; i < action.from.Count; i++)
                    {
                        output += string.Format("x: {0} y: {1} => x: {2} y: {3}", action.from[i].x, action.from[i].y, action.to[i].x, action.to[i].y);
                    }
                    break;
                case Board.Action.Type.ComboBegin:
                    output += "ComboBegin\n";
                    break;
                case Board.Action.Type.ComboEnd:
                    output += "ComboEnd\n";
                    break;
            }
        }
        return output;
    }
}